package com.gy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import com.gy.File.fileInfo;
import com.gy.mapper.FileInfoServiceMapper;
import com.gy.service.FileInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FileInfoServiceImpl extends ServiceImpl<FileInfoServiceMapper, fileInfo> implements FileInfoService {

    @Autowired
    private FileInfoServiceMapper fileInfoServiceMapper;

    @Override
    public fileInfo getByFileHash(String fileHash) {
        return fileInfoServiceMapper.selectByFileHash(fileHash);
    }

    // 保存文件信息
    @Override
    public boolean savefileInfo(fileInfo fileInfo) {
        return this.save(fileInfo);
    }

    @Override
    public boolean deleteByFileHash(String fileHash) {
        return this.lambdaUpdate().eq(fileInfo::getFileHash, fileHash).remove();
    }

    // 实现根据文件路径查询文件信息
    @Override
    public fileInfo getByFilePath(String filePath) {
        // 构造查询条件：where file_path = ?
        QueryWrapper<fileInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("file_path", filePath);
        // 调用MyBatis-Plus的方法查询单条记录
        return baseMapper.selectOne(queryWrapper);
    }
}
